//////////////////////////////////////////////////////////////////////////////
//
//  Created by Philip Mulcahy on 01/03/2013.
//  Copyright (c) 2013 Philip Mulcahy. All rights reserved.
//
//  This file is part of the note-recog library.
//
//  note-recog is free software: you can redistribute it and/or modify
//  it under the terms of version 3 of the GNU Lesser General Public License 
//  as published by the Free Software Foundation.
//
//  note-recog is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with note-recog. If not, see <http://www.gnu.org/licenses/>.
//
//////////////////////////////////////////////////////////////////////////////


#include "ParametricFrameGenerator.h"
#include "Frame.h"
#include "IFrameGenParamGen.h"
#include "FastFourierTransform.h"
#include "Spectrum.h"


ParametricFrameGenerator::ParametricFrameGenerator(IFrameGenParamGen* paramGen,
                                                   float samplingFreq,
                                                   size_t frameSize)
: _frameGenParamGen(paramGen),
  _samplingFreq(samplingFreq),
  _timeDomain(*paramGen, samplingFreq, frameSize)
{}


ParametricFrameGenerator::~ParametricFrameGenerator()
{
    delete _frameGenParamGen;
}


Frame ParametricFrameGenerator::next()
{
    std::pair<float, std::vector<short> > td = _timeDomain.next();
    FastFourierTransform::Functor fft(_samplingFreq);
    Frame frame(td.second, td.first, _samplingFreq);
    return frame;
}


bool ParametricFrameGenerator::hasNext() const
{
    return _timeDomain.hasNext();
}